package statistics;

import java.awt.Color;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogarithmicAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.DatasetRenderingOrder;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;

public class SimulationGraph {
	
	public XYSeriesCollection dataset = new XYSeriesCollection();
	
	public SimulationGraph(){

	}
	
	public void show(){
	    final JFreeChart diameterChart = createDiameterChart("Skew vs Diameter");
	    final ChartPanel panel = new ChartPanel(diameterChart);
	    panel.setPreferredSize(new java.awt.Dimension(500, 270));  
	    ApplicationFrame a1 = new ApplicationFrame("");    
	    a1.setContentPane(panel);	    
	    a1.pack();	    
	    a1.setVisible(true);
	}
	
		
	private JFreeChart createDiameterChart(String title) {
		
	    final ValueAxis time = new NumberAxis("Diameter");    
        final NumberAxis rangeAxis = new LogarithmicAxis("Skew (microsecond)");
//        final NumberAxis rangeAxis = new NumberAxis("Skew (microsecond)");
			
        
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        
        final XYPlot plot = new XYPlot(dataset, time, rangeAxis, renderer);
//        final XYPlot plot = new XYPlot(dataset, time, skew, renderer);
        
        renderer.setLinesVisible(true);
        renderer.setShapesVisible(true);
        
        renderer.setSeriesPaint(0, Color.BLACK);
        renderer.setSeriesPaint(1, Color.BLUE);
        renderer.setSeriesPaint(2, Color.RED);
        renderer.setSeriesPaint(3, Color.ORANGE);
        renderer.setSeriesPaint(4, Color.CYAN);
        
//        renderer.setSeriesPaint(0, Color.BLACK);
//        renderer.setSeriesPaint(1, Color.BLACK);
//        renderer.setSeriesPaint(2, Color.BLUE);
//        renderer.setSeriesPaint(3, Color.BLUE);
//        renderer.setSeriesPaint(4, Color.RED);
//        renderer.setSeriesPaint(5, Color.RED);
//        renderer.setSeriesPaint(6, Color.ORANGE);
//        renderer.setSeriesPaint(7, Color.ORANGE);
//        renderer.setSeriesPaint(8, Color.CYAN);
//        renderer.setSeriesPaint(9, Color.CYAN);
        
               
//        renderer.setSeriesLinesVisible(0, true);
//        renderer.setSeriesShapesVisible(0, false);
//                
//        renderer.setSeriesLinesVisible(1, true);
//        renderer.setSeriesShapesVisible(1, true);   
//        
//        renderer.setSeriesLinesVisible(2, true);
//        renderer.setSeriesShapesVisible(2, false);
////        renderer.setSeriesPaint(2, Color.black);
//        
//        renderer.setSeriesLinesVisible(3, true);
//        renderer.setSeriesShapesVisible(3, true);     
//        
//        renderer.setSeriesLinesVisible(4, true);
//        renderer.setSeriesShapesVisible(4, true);   
               
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
        plot.setOrientation(PlotOrientation.VERTICAL);
        //plot.getDomainAxis().setRange(10,70);
        
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);

        return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
	}
}
